/**

 * Creates an empty Stack.
 * Inherit from Cloneable
 * @author	Wan Changhua
 * @version	2.01, 10/23/05 $Id: Stack.js 35 2008-03-02 17:01:34Z dsonet $
 * @extends Cloneable
 * @class This is the stack class.
 * @constructor
 */
function Stack ()
{
	/*
	 * @private
	 */
	this._list = new ArrayList;
}

var $p = Type.extend(Stack, Cloneable).prototype;

/**
 * Tests if this stack is empty.
 * @return  <code>true</code> if and only if this stack contains
 *		  no items; <code>false</code> otherwise.
 * @type boolean
 */
$p.empty = function()
{
	return (this._list.size() == 0);
}

/**
 * Looks at the object at the top of this stack without removing it 
 * from the stack. 
 *
 * @return	 the object at the top of this stack (the last item 
 *			 of the <tt>Vector</tt> object).
 * @type Object
 */
$p.peek = function()
{
	if (this.empty())
	{
		return null;
	}
	var o = this._list.get(0);
	return o;
}

 /**
  * Removes the object at the top of this stack and returns that 
  * object as the value of this function. 
  *
  * @return	 The object at the top of this stack (the last item 
  *			 of the <tt>Vector</tt> object).
  * @type Object
  */
$p.pop = function()
{
	if (this.empty())
	{
		return null;
	}
	var o = this._list.get(0);
	this._list.removeAt(0);
	return o;

}

/**
 * Pushes an item onto the top of this stack. This has exactly 
 * the same effect as:
 * <blockquote><pre>
 * addElement(item)</pre></blockquote>
 * @public
 * @param {mixed} o   the item to be pushed onto this stack.
 * @return  the <code>item</code> argument.
 * @id Stack.prototype.push
 * @type void
 */
$p.push = function(o)
{
	this._list.add(0, o);
}


/**
 * Returns the 1-based position where an object is on this stack. 
 * If the object <tt>o</tt> occurs as an item in this stack, this 
 * method returns the distance from the top of the stack of the 
 * occurrence nearest the top of the stack; the topmost item on the 
 * stack is considered to be at distance <tt>1</tt>. The <tt>equals</tt> 
 * method is used to compare <tt>o</tt> to the 
 * items in this stack.
 *
 * @param {mixed} o   the desired object.
 * @return  the 1-based position from the top of the stack where 
 *		  the object is located; the return value <code>-1</code>
 *		  indicates that the object is not on the stack.
 * @type Object
 */
$p.contains = function(o)
{
	return this._list.contains(o);
}

/**
 * Returns a shallow copy of this <tt>Stack</tt> instance.  (The
 * elements themselves are not copied.)
 *
 * @return  a clone of this <tt>Stack</tt> instance.
 * @type Stack
 */
$p.clone = function()
{
	var o = new this;
	o._list = this._list.clone();
	return o;
}
$p.toArray = function()
{
	return [].concat(this._list);
}

$p = null;